# 批量扫描指定网段内的存活IP
import IPy
from pythonping import ping
from multiprocessing import Process
import threading


def myping(ip):
    res = ping(ip, timeout=1)
    if res.success():
        print(str(ip) + " is up")
    else:
        print(str(ip) + " is down")

# 多进程实现
if __name__ == "__main__":
    ip_net = "192.168.10.0/24"
    ips = IPy.IP(ip_net)

    p_lst = []
    for ip in ips:
        p = Process(target=myping, args=(str(ip),))
        p_lst.append(p)
        p.start()
    [p.join() for p in p_lst]
    print("end...")


# # 多线程实现
# ip_net = "192.168.10.0/24"
# ips = IPy.IP(ip_net)
# for ip in ips:
#     t = threading.Thread(target=myping, args=(str(ip),))
#     t.start()